<?php

/**
 * Radcodes - SocialEngine Module
 *
 * @category   Application_Extensions
 * @package    Badge
 * @copyright  Copyright (c) 2009-2010 Radcodes LLC (http://www.radcodes.com)
 * @license    http://www.radcodes.com/license/
 * @version    $Id$
 * @author     Vincent Van <vincent@radcodes.com>
 */

class Badge_Form_Admin_Award_Add extends Engine_Form {
	public function init() {
		
		$this->setTitle ( 'Add Member Award' )->setDescription ( 'To get started, please enter member ID or email or username whom would like to give award to.' );
		
		$this->addElement ( 'text', 'user', array ('label' => 'Member', 'description' => 'Enter Member ID or Email or Username', 'allowEmpty' => false, 'required' => true, 'filters' => array ('StringTrim' ), 'validators' => array ('NotEmpty', new Engine_Validate_Callback ( array ($this, 'validateMember' ) ) ), 'style' => 'width: 98%' ) );
		$this->user->getDecorator ( 'Description' )->setOption ( 'placement', 'append' );
		
		// Submit
		$this->addElement ( 'Button', 'submit', array ('label' => 'Continue', 'ignore' => true, 'decorators' => array ('ViewHelper' ), 'type' => 'submit' ) );
		
		//
		

		$createUrl = Zend_Controller_Front::getInstance ()->getRouter ()->assemble ( array ('module' => 'badge', 'controller' => 'awards', 'action' => 'create' ), 'admin_default', true );
		
		$this->addElement ( 'Cancel', 'skip', array ('prependText' => ' - ', 'label' => 'Skip Wizard', 'link' => true, //'href' => 'javascr',
		'onclick' => 'parent.window.location.href="' . $createUrl . '";', 'decorators' => array ('ViewHelper' ) ) );
		
		$this->addElement ( 'Cancel', 'cancel', array ('prependText' => ' or ', 'label' => 'cancel', 'link' => true, //'href' => 'javascr',
		'onclick' => 'parent.Smoothbox.close();', 'decorators' => array ('ViewHelper' ) ) );
		
		$this->addDisplayGroup ( array ('submit', 'skip', 'cancel' ), 'buttons' );
		$button_group = $this->getDisplayGroup ( 'buttons' );
	}
	
	public function validateMember($value) {
		/*
    // Not string?
    if( !is_string($value) || empty($value) ) {
      $this->user->getValidator('Engine_Validate_Callback')->setMessage('Please complete this field - it is required.');
      return false;
    }
		*/
		
		$user = Engine_Api::_ ()->user ()->getUser ( $value );
		if (! $user->getIdentity ()) {
			$this->user->getValidator ( 'Engine_Validate_Callback' )->setMessage ( 'Could not find user %value%' );
			return false;
		}
		
		return true;
	}
}